<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="but">按钮</button>
    <script>
    var flag = true  ;
    var age = 20    ;
    var but = document.getElementsByClassName(`but`)[0]
     but.onclick = function(){
        flag = !flag
        var res = `我的名字${flag?`张三`:`李四`};我的年龄${age+1}`
        alert(res)
     }

    </script>
</body>
</html>